Skip to content

refactor(codegen-kotlin): move Exposed, relations, repository and extract generators onto KotlinWriter - #659

Merged
dmealing merged 3 commits into
mainfrom
fm/mo-130-kt-writer-2
Nov 26, 2026
Merged

dmealing merged 3 commits into
mainfrom
fm/mo-130-kt-writer-2

Conversation

@dmealing

@dmealing dmealing commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Moves KotlinExposedTableGenerator, KotlinRelationsGenerator, KotlinRepositoryGenerator and KotlinExtractSchemaEmitter onto KotlinWriter (ADR-0063) and drops their own KotlinPoet layout. Their four entries leave the codegen-kotlin layout-ratchet allowlist. KotlinNaming stays listed because ejected copies still call packageHeader.
  • KotlinWriter.needsImport now imports a dotless (root-package) name unless the file is itself in the root package. The replaced generators relied on this import, and dropping it would break compilation. Adds two kotlin-imports-root-package* writer-conformance cases (a named-package file imports the name; a root-package file does not) and a spec/code-writer.md line; the writer-conformance case count moves 86 to 88.
  • The 17 changed Kotlin golden snapshots differ in layout only: sorted import group, blank-line placement at class and companion body starts and at file end, a one-line extract mirror property, and KDoc wrapping. No generated behavior or compiled semantics change. Verified by the codegen-kotlin suite (714 tests, 0 failures), the Exposed 1.x round-trip check (5/0) and integration-tests-kotlin (462/0, 7 pre-existing skips).

Evidence

Every golden diff is layout only. The 17 changed snapshot files show only: imports in one sorted group, no blank line at the start of a class or companion body, no trailing blank line at the end of a support file, a one-property extract mirror on one line, an over-long one-line KDoc written as a block, and a blank line after the extract mirror's header comment. The repository @autoSet KDoc keeps its hanging indent. The pipeline's review compared the seven support-file bodies against the old builders, whitespace-normalised, and found them identical.

Suites run locally on this change before the gate (these are the live evidence for the change; the gate's Test step recorded "no live scenario driven", and the operator accepted these runs in its place):

Suite Result
codegen-kotlin full suite (snapshot goldens, CodegenCompileConformanceTest compile gate, EjectedAtBaseGeneratorsCompatTest, writer conformance, layout ratchet) 714 tests, 0 failures (713 baseline + the new writer case)
codegen-kotlin-exposed1x-check (Exposed 1.x compile + round trip against Testcontainers Postgres) 5 tests, 0 failures
integration-tests-kotlin (Exposed 0.x persistence corpus + generated api-contract lanes against Testcontainers Postgres) 462 tests, 0 failures, 7 skipped (pre-existing)
scripts/ci-local.sh --only gates passed

The gate's own Test command (scripts/ci-local.sh --affected --strict-toolchains, every port lane) passed. The second root-package case was added by the gate's fix round after review.

no-mistakes: 1 run (outcome passed-with-override: the Test step's "no live run" verdict was approved by the operator on the evidence above).

Validation

Risk Assessment

✅ Low: A mechanical port onto KotlinWriter whose support-file text matches the old builders line for line, whose import sets match for both Exposed APIs, and whose one writer behaviour change, the root-package import, keeps the imports the old generators wrote; the only finding is a missing negative conformance case.

Testing

Ran the Kotlin and core writer conformance corpora through their test runners (44 and 40 cases, all passing). These cover the root-package import rule. None of the scenarios were driven live: the Kotlin root-package import case and the core engine case are unit-level conformance results, and the four converted generators' output was not generated from a fixture and checked. The layout-only claim is therefore unverified by live run. Verdict inconclusive; open item is whether a live generate run is required.

  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin writer root-package import rule: named-package file imports dotless name, root-package file does not (writer conformance corpus, KotlinWriterConformanceTest) ⏸️ untested no Only the conformance test runner was executed (server/java: mvn -o -pl codegen-kotlin -am -Dtest=KotlinWriterConformanceTest,WriterConformanceTest test; 44 run, 0 failures). That is not a live drive o…
Core writer engine conformance (WriterConformanceTest, 40 cases) still green after writer change ⏸️ untested no Only the unit-level conformance test runner was executed (40 run, 0 failures). Not a live drive of the product, so it cannot be recorded as a pass.
Live Exposed table, relations, repository and extract output from codegen-kotlin Maven generate on a fixture, layout-only diff vs base commit ⏸️ untested no Not driven: would need mvn metaobjects:generate on a fixture plus a base-commit comparison; not run within the time budget. Offline Maven reactor build worked with -am, so this is feasible follow-up w…
Evidence: Writer conformance surefire reports (Kotlin 44/0, core 40/0)
-------------------------------------------------------------------------------
Test set: com.metaobjects.generator.kotlin.writer.KotlinWriterConformanceTest
-------------------------------------------------------------------------------
Tests run: 44, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.324 s -- in com.metaobjects.generator.kotlin.writer.KotlinWriterConformanceTest
-------------------------------------------------------------------------------
Test set: com.metaobjects.generator.writer.WriterConformanceTest
-------------------------------------------------------------------------------
Tests run: 40, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.113 s -- in com.metaobjects.generator.writer.WriterConformanceTest
  • Outcome: ✅ passed with an operator-approved Test exception (2 "no live run" warnings, resolved by decision); review-1 fixed

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - 1 info, resolved
  • ℹ️ fixtures/writer-conformance/cases/kotlin-imports-root-package.json:2 - The new writer case's description claims two behaviours: a file in a named package imports a dotless (root-package) name, and a file in the root package does not. Only the first is exercised; the root-package side of KotlinWriter.needsImport (pkg == "" && packageName empty -> no line) has no case, so a later 'always import dotless names' simplification would pass this fixture. Add a sibling case (no package op, or package "") expecting just val t = RootTable with no import line (oracle: Kotlin spec, a root-package name is visible unqualified in another root-package file).

✅ Resolved: the gate's fix round added fixtures/writer-conformance/cases/kotlin-imports-root-package-same-file.json (a root-package file writes val t = RootTable with no import line) and moved the writer-conformance count to 88 (12 Kotlin); KotlinWriterConformanceTest 44/0.

✅ **Test** - passed with operator-approved exception (2 "no live run" warnings)
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Generated Exposed table/relations/repository/extract output changes only in layout (fixture generated via codegen-kotlin), Root-package dotless name import: named-package file imports RootTable, root-package file does not, Generated Exposed output still compiles and round-trips on Postgres
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Generated Exposed table/relations/repository/extract output changes only in layout (fixture generated via codegen-kotlin) ⏸️ untested no Covered by golden/unit tests only. A live drive needs the metaobjects Maven plugin or a CLI run on a fixture, which I did not set up in this turn.
Root-package dotless name import: named-package file imports RootTable, root-package file does not ⏸️ untested no Exercised by the writer-conformance unit test, not by a live generator run on a fixture.
Generated Exposed output still compiles and round-trips on Postgres ⏸️ untested no Needs Testcontainers Postgres and is an integration lane; not re-driven here (broad regression is the configured command).
  • scripts/ci-local.sh --affected --strict-toolchains
  • mvn -o -q -pl codegen-kotlin -am test -Dtest='KotlinWriterConformanceTest,*Exposed*,*Relations*,*Repository*,*ExtractSchema*' -Dsurefire.failIfNoSpecifiedTests=false in server/java (exit 0)
  • Surefire report summary in server/java/codegen-kotlin/target/surefire-reports: 713 tests, 0 failures, 0 errors (count matches the baseline in the intent; the report dir may include prior runs)
  • Read fixtures/writer-conformance/cases/kotlin-imports-root-package.json (root-package import case pinned by KotlinWriterConformanceTest)

🔧 Fix applied (review-1).
✅ Resolved by operator decision: the two "no live run" warnings below were approved as a Test exception on the local evidence listed under Evidence above (codegen-kotlin 714/0, Exposed 1.x Postgres round trip 5/0, integration-tests-kotlin 462/0).

  • ⚠️ No live scenario driven: Exposed table, relations, repository and extract output (layout-only change) not generated and checked through the real codegen-kotlin Maven generate goal on a fixture. Evidence is the writer conformance tests only, which are not live. Needs a live generate run or a human decision to accept the existing codegen-kotlin suite as sufficient.
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Kotlin writer root-package import rule: named-package file imports dotless name, root-package file does not (writer conformance corpus, KotlinWriterConformanceTest), Core writer engine conformance (WriterConformanceTest, 40 cases) still green after writer change, Live Exposed table, relations, repository and extract output from codegen-kotlin Maven generate on a fixture, layout-only diff vs base commit
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin writer root-package import rule: named-package file imports dotless name, root-package file does not (writer conformance corpus, KotlinWriterConformanceTest) ⏸️ untested no Only the conformance test runner was executed (server/java: mvn -o -pl codegen-kotlin -am -Dtest=KotlinWriterConformanceTest,WriterConformanceTest test; 44 run, 0 failures). That is not a live drive o…
Core writer engine conformance (WriterConformanceTest, 40 cases) still green after writer change ⏸️ untested no Only the unit-level conformance test runner was executed (40 run, 0 failures). Not a live drive of the product, so it cannot be recorded as a pass.
Live Exposed table, relations, repository and extract output from codegen-kotlin Maven generate on a fixture, layout-only diff vs base commit ⏸️ untested no Not driven: would need mvn metaobjects:generate on a fixture plus a base-commit comparison; not run within the time budget. Offline Maven reactor build worked with -am, so this is feasible follow-up w…
  • scripts/ci-local.sh --affected --strict-toolchains
  • Confirmed review-1 fix present: fixtures/writer-conformance/cases/kotlin-imports-root-package-same-file.json exists and docs/CONFORMANCE.md reads 88 cases (12 Kotlin).
  • mvn -q -o -pl codegen-kotlin -am -Dtest=KotlinWriterConformanceTest,WriterConformanceTest test in server/java: exit 0, KotlinWriterConformanceTest 44 run / 0 failures, WriterConformanceTest 40 run / 0 failures.
  • Baseline scripts/ci-local.sh --affected --strict-toolchains already passed at target commit; no source or test files changed in this turn, so no re-run.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The Exposed table generator (the table object and its seven per-package
support files), the relation helpers, the repository base and the extract
mirror now write through KotlinWriter (ADR-0063) and no longer import
KotlinPoet; they read the type mapper's KotlinPoet types by qualified name
until W-KT-4 retires it. Their four entries leave the layout ratchet's
allowlist.

Generated output changes in layout only: sorted imports, no blank line at
the start of a body or the end of a support file, a short parameter list on
one line, a long KDoc as a block, a blank line after a header comment. The
snapshot goldens are refreshed to match.

KotlinWriter now imports a root-package name into a file in a named
package, as the replaced generators did; a new kotlin writer case pins it.
…ount in docs/ports/kotlin.md replaced with a pointer to ADR-0063 and the ratchet allowlist.
@dmealing
dmealing merged commit 9137b33 into main Nov 26, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-kt-writer-2 branch November 26, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant